{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Monte Carlo Positioning"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will learn how to program vehicles with the ability to sense their own location, and the locations of other vehicles, using sensors and algorithms."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this lecture we will learn to sense locations with Monte Carlo positioning."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![http://www.fix.com/blog/driverless-car-revolution/](driverless-car.png \"Driverless Car\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%matplotlib inline "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import scipy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def show_world(ax, lw=5):\n",
    "    #show a world with lw cells\n",
    "    \n",
    "    ax.bar(np.arange(lw), np.ones(lw), 1, linewidth=3)\n",
    "    ax.spines['right'].set_color('none')\n",
    "    ax.spines['left'].set_color('none')\n",
    "    ax.spines['top'].set_color('none')\n",
    "    ax.xaxis.set_ticks_position('bottom')\n",
    "    ax.set_xticks(np.arange(lw)+0.5)\n",
    "    #ax.set_xlim([-0.1, 5.1])\n",
    "    #ax.set_ylim([0, 110])\n",
    "    ax.set_xticklabels(np.arange(lw)+1)\n",
    "    plt.yticks([])\n",
    "\n",
    "def showbar(ax, center=range(1,6,1), height=0.5, bottom=0.25, color='red'):\n",
    "    #show markers on the positions (center)\n",
    "    \n",
    "    ax.bar(np.array(center)-1+0.1, height, bottom=bottom, color=color, linewidth=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "input_collapsed": false
   },
   "source": [
    "## Discrete 1D World"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Rather than start from a vehicle in continuous 3D world, we are going to consider a dicrete 1D world firstly.\n",
    "\n",
    "Image a train on the track,  where it is only possible to move forward or backwards; sideways motion is impossible. The measurement is so rough that there are only 5 positions. If there are more accurate measurement methods, we may divide the track into 500 intervals."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABExJREFUeJzt3M+rpQMcx/HP/CAGkShEjaWFomShmWaiJEn+BQtbC2Xh\nL7CclZ0sRLMSkZ1yImU0mWkwsqIUJkVKysZYPGdhM3Nn8el+z3Fer805de6tT92ne9/nOc99EgAA\nAAAAAAAAAAAAAAAAADbXgT1ev7wvKwAA2BZX7MeD+7kCAID/r8PX9mVOXO6u/74pcRzsJscAieOA\nheOAq3/Y7YwlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIAgAph\nCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCo\nEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIA\ngAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEs\nAQCoEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAV\nwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIA\nUCEsAQCoEJYAAFQISwAAKoQlAAAVwhIAgAphCQBAhbAEAKBCWAIAUCEsAQCoEJYAAFQISwAAKoTl\nnlbTA9gIq+kBjFtND2AjrKYHMG41PWCjCcs9raYHsBFW0wMYt5oewEZYTQ9g3Gp6wEYTlgAAVBzY\n4/XL+7ICAIBtccV+PHQN33iyOgUAgG12IK4JAAAAAAAAAAAAAKDgjSSXknw1PYQx9yX5OMk3Sb5O\n8uLsHIbckORMkvNJLiZ5dXYOgw4lOZfkg+khjPkhyYUsx8EXs1PYNseTPBxhucvuSvLQ+vnNSb5L\n8sDcHAYdWT8eTvJ5kmODW5jzUpK3k7w/PYQx3ye5fXrEJnOD9Cv7NMnv0yMY9UuWs1RJ8meSb5Pc\nMzeHQX+tH6/Pctbqt8EtzLg3ydNJXs/e94Dm/83P/yqEJVybo1nOYJ8Z3sGMg1neZFzKcnnExdk5\nDDiV5OUk/0wPYdTlJB8lOZvkheEtbKGj8VE4y8fgZ5M8Nz2Ecbdm+Sj85PAO9tczSV5bPz8Z11ju\nsrvXj3dmebN5fHDLRnLGEq7uuiTvJHkryXvDW5j3R5IPkzwyPYR99ViSZ7NcX3c6yeNJ3hxdxJSf\n14+/Jnk3yaODW9hCR+OM5S47kOWPx6npIYy6I8lt6+c3JvkkyRNzcxh2Is5Y7qojSW5ZP78pyWdJ\nnpybw7Y5neSnJH8n+THJ87NzGHAsy/VU57PcWuJckqdGFzHhwSRfZjkOLmS5zo7ddSL+K3xX3Z/l\n98D5LLege2V2DgAAAAAAAAAAAAAAAAAAAAAAAAAAbK9/AdXhWVuWC0PgAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0b701cc>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Deterministic World"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The world is also deterministic, which means that the train is at one of the positions with the probability of 100%."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us try to locate it. Assume for some reason we know it starts from cell 1, but the measurement tells us that it is at cell 5. So where is it on earth?\n",
    "* Prior: cell 1 (in red)\n",
    "* Measurement: cell 5 (in green)\n",
    "* Posterior: ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABQ1JREFUeJzt3LGLHHUYx+HvJlE03qGIgorCWVoICmIhCTkURETEf8HC\n1kKwsLvOSlLZiYUoqcSg2AkuimAkmCNqxEpBUIOgiEGw8SxmiwS87OXyuu/s7fPAMgt7t7wwv7v9\n7MzsJgAAAAAAAAAAAAAAAAAAAIzXZM7jOwuZAgCAZbFrPx5a5BQAABxcR/b2Yw5crq7L35RYB6vJ\nGiCxDhhYB1z9ZLcjlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQ\nlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQoDsvXkqwnmbiN9rY+\n208AsAjaYNy32i6YzHl854rNXOtJLl3HOCzGWpI/9/izly+Rva4DDhZrgMQ6YLCfdaANxu+au2DX\nfiwOy3lPx3jsZ596MVlN1gCJdcBgP+tAGyyHa9qfu+7UIyWz/Af/dsbHnzYArba6B+AKW/VP6cM7\nAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAA\nlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQ\nlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYAAJQQlgAAlBCWAACUEJYA\nAJQQlgAAlBCWAACUEJYAAJQQlgAAlJjMeXznis11Px3jsZ99utff4WCxBkisAwb7WQfaYDlc0/7c\ndacWH7Fcq306/if2EwCL4jVn/Or2UXFYbsUCGru1DPsJABZhK9pgzGq7oPhUOAeP019YAyTWAQPr\ngIWeCgcAYFUJSwAASghLAABKCEsAAEoISwAASghLAABKCEsAAEoISwAASghLAABKCEsAAEoISwAA\nSghLAABKCEsAAEoISwAASghLAABKCMu5pt0DMArT7gFoN+0egFGYdg9Au2n3AKMmLOeadg/AKEy7\nB6DdtHsARmHaPQDtpt0DjJqwBACgxGTO4zsLmQIAgGWxaz8e3sMvbpaOAgDAMpvENQEAAAAAAAAA\nAAAAFHgzycUkX3UPQpv7knyc5JskXyd5sXccmtyU5EyS7SQXkrzaOw6NDic5l+SD7kFo80OS8xnW\nwRe9o7Bsjid5OMJyld2V5KHZ/bUk3yV5oG8cGh2dbY8k+TzJscZZ6PNSkneSvN89CG2+T3J79xBj\n5gvSd/dpkt+7h6DVLxmOUiXJpSTfJrmnbxwa/TXb3pjhqNVvjbPQ494kTyd5I/O/A5qDzf6/CmEJ\ne7OR4Qj2meY56HEow5uMixkuj7jQOw4NTiZ5Ock/3YPQaifJR0nOJnmheRaW0EacCmc4DX42yXPd\ng9Du1gynwjeb52Cxnkny+uz+Zlxjucrunm3vzPBm83jjLKPkiCVc3Q1J3k3ydpLTzbPQ748kHyZ5\npHsQFuqxJM9muL7uVJLHk7zVOhFdfp5tf03yXpJHG2dhCW3EEctVNsnw4nGyexBa3ZHkttn9m5N8\nkuSJvnFodiKOWK6qo0nWZ/dvSfJZkif7xmHZnEryU5K/k/yY5PnecWhwLMP1VNsZvlriXJKnWiei\nw4NJvsywDs5nuM6O1XUiPhW+qu7P8H9gO8NX0L3SOw4AAAAAAAAAAAAAAAAAAAAAAAAAACyvfwEx\nN4DuKz4B1QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0b8fe6c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "# Prior position: cell 1 (in red)\n",
    "showbar(ax, 1, color='red')\n",
    "# Measurement: cell 5 (in green)\n",
    "showbar(ax, 5, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Posterior position? "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABS9JREFUeJzt3DGLXGUUBuB3kigad1FEQUUhlhaCglhIQoKCiIj4Fyxs\nLQQLu+2sJJWdWIiSShTFTnBQBCPBhKgRKwVBDYIiBsHGtbhTJOBmdjcnc+7MPA8Md2B2hxe+b8++\ne+/dSQAAAAAAAAAAAAAAAAAAABivyZzXtxeSAgCAZbFjfzywyBQAAKyuQ7v7Micu19flf5TYB+vJ\nHiCxDxjYB1z9YrczlgAAlFAsAQAooVgCAFBCsQQAoIRiCQBACcUSAIASiiUAACUUSwAASiiWAACU\nUCwBACihWAIAUEKxBACghGIJAEAJxRIAgBKKJQAAJRRLAABKKJYAAJRQLAEAKFFcLF9Lsplk4jHa\nx+ZsneB6MgvG/zALWBTzYNyP2lkwmfP69hWHuTaTXLqGOCzGRpK/dvm1l2+R3e4DVst+9oBZsBzM\nAvbKPFhNe54FO/bH4mI57+0Yj/2sqV8m62k/e8AsWB5mAXthHqyuPa3njot6qCTL/zB2xsePNh22\nDYPRmRgGdNnqDsAVturf0j/vAABQQrEEAKCEYgkAQAnFEgCAEoolAAAlFEsAAEoolgAAlFAsAQAo\noVgCAFBCsQQAoIRiCQBACcUSAIASiiUAACUUSwAASiiWAACUUCwBACihWAIA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J/hPjvW1/H4r/B1dX+G\nOXAuw0fQvdIbBwAAAAAAAAAAAAAAAAAAAAAAAAAAltd/dEiJuTINMzsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0a9cc4c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "# Prior position: cell 1 (in red)\n",
    "showbar(ax, 1, color='red')\n",
    "# Measurement: cell 5 (in green)\n",
    "showbar(ax, 5, color='green')\n",
    "\n",
    "# Posterior position: cell 3 (in yellow)\n",
    "showbar(ax, 3, color='yellow')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Just the middle of cell 1 and cell 5, that is, cell 3?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABTVJREFUeJzt3DGLXGUUBuB3kigad1FEQUUhlhaCglhIQoKCiIj4Fyxs\nLQQLu+2sJJWdWIiSShTFTnBQBCPBhKgRKwVBDYIiBsHGtbhTJOBmNpszc+7sPA8Md2B2Jy98J/u9\ne+/dSQAAAAAAAAAAAAAAAAAAABivyZzXt5eSAgCAVbFjfzywzBQAAOxfh3b3ZU5crq/LfykxB+vJ\nDJCYAwbmgKtf7HbGEgCAEoolAAAlFEsAAEoolgAAlFAsAQAooVgCAFBCsQQAoIRiCQBACcUSAIAS\niiUAACUUSwAASiiWAACUUCwBACihWAIAUEKxBACghGIJAEAJxRIAgBKKJQAAJYqL5WtJNpNMPEb7\n2JytE8Ci2RPG/1jGnmAOxv2onYHJnNe3rzjMtZnk0nXEYTk2kvy1y6+9fER2OwfsL2aAZG9zYE9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v\nz56fiHss19nds+OdGX7ZPNaYZZScsYSruyHJu0neTvJ+cxb6/ZnkoySPdAdhqR5L8myG++tOJXk8\nyVutiejyy+z4W5L3kjzamIUVdCTOWK6zSYbN42R3EFrdkeS22fObk3ya5Im+ODQ7Hmcs19XhJJuz\n57ck+TzJk31xWDWnkvyc5J8kPyV5vjcODY5muJ/qXIaPljib5KnWRHR4MMlXGebgfIb77Fhfx+Ov\nwtfV/Rl+DpzL8BF0r/TGAQAAAAAAAAAAAAAAAAAAAAAAAACA1fUfluKJucTQNCIAAAAASUVORK5C\nYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0b8f8ec>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "# Prior position: cell 1 (in red)\n",
    "showbar(ax, 1, color='red')\n",
    "# Measurement: cell 5 (in green)\n",
    "showbar(ax, 5, color='green')\n",
    "\n",
    "# Posterior position: cell 4 (in yellow)\n",
    "showbar(ax, 4, color='yellow')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Closer to cell 5, that is, cell 4?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABSdJREFUeJzt3LGrW3UYBuA3bRWt96KIgopCHR0EBXGQlhYFERHxX3Bw\ndRAc3O7mJJ3cxEGUTqIoboJBEawUW6pWnBQEtQiKWAQXr8NJoQVvc9t+N99J8jwQTiC54YXfd3Pe\nnHOSBAAAAAAAAAAAAAAAAAAAgPGazHl8eyEpAABYFjv2x32LTAEAwOo6sLunOXC5vi79UGIO1pMZ\nIDEHDMwBVz7Z7YglAAA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S27tDjJkfSN/ZZ0n+6A5Bq18zHKVKkgtJvktyT18cGv09\n296Y4ajV741Z6HFvkqeTvJH5vwHNarP+V6BYwu4cynAE+2RzDnrsy/Ah43yGyyPO9cahwfEkLyf5\ntzsIrbaTfJzkVJIXmrOwhA7FqXCG0+CnkjzXHYR2t2Y4FX6sOQeL9UyS12f3j8U1luvs7tn2zgwf\nNo80ZhklRyzhym5I8m6St5O835yFfn8m+SjJI91BWKjHkjyb4fq6E0keT/JWayK6/DLb/pbkvSSP\nNmZhCR2KI5brbJJh53G8Owit7khy2+z+zUk+TfJEXxyaHY0jluvqYJLN2f1bknye5Mm+OCybE0l+\nTvJPkp+SPN8bhwaHM1xPdSbDT0ucTvJUayI6PJjkqwxzcDbDdXasr6PxrfB1dX+G94EzGX6C7pXe\nOAAAAAAAAAAAAAAAAAAAAAAAAAAAsLz+A77CibhRDbmsAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0b69c2c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "# Prior position: cell 1 (in red)\n",
    "showbar(ax, 1, color='red')\n",
    "# Measurement: cell 5 (in green)\n",
    "showbar(ax, 5, color='green')\n",
    "\n",
    "# Posterior position: cell 2 (in yellow)\n",
    "showbar(ax, 2, color='yellow')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Closer to cell 1, that is, cell 2?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Probabilistic World"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Prior: [0.2, 0.5, 0.2, 0.05, 0.05] (in red)\n",
    "\n",
    "* Measurement: [0.05, 0.05, 0.1, 0.7, 0.1] (in green)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABcRJREFUeJzt3UGrXIUZBuB3kqtoegeltGCLhbh0UVAQF5KQUEGklNK/\n4MJtF0IX3WXnKmTVnbgQJStRlO4Eh4pgJJgQ25SuWihUg1ApCYVuel2cQZPFvTO5fjPfmZnngZMz\ncGbu/eC8OfedM2dmEgAAAAAAAAAAAAAAAAAAAMZrsmD7wVqmAABgUxzaH0+scwoAALbX3nJ3c+Jy\nd939pEQOdpMMkMgBAzng6Be7nbEEAKCEYgkAQAnFEgCAEoolAAAlFEsAAEoolgAAlFAsAQAooVgC\nAFBCsQQAoIRiCQBACcUSAIASiiUAACUUSwAASiiWAACUUCwBACihWAIAUEKxBACghGIJAEAJxZIV\nuJhkmmRiGeUyne8jAKg1WbD94J4VO+juiCybg2mSOyuYhTr7SW4ved/jZIDtIwckcsA8A4f2R8WS\nBY5zEFkUK8bhOPvTsWB3yQGJHLCoWO6tbxB2kcPOuKj8AKySaywBACihWAIAUEKxBACghGIJAEAJ\nxRIAgBKKJQAAJRRLAABKKJYAAJRQLAEAKKFYAgBQQrEEAKCEYgkAQAnFEgCAEoolAAAlFEsAAEoo\nlgAAlFAsAQAooVgCAFBCsQQAoIRiCQBACcUSAIASiiUAACWKi+XFJNMkE8tol+l8P8EqORaMf3Es\nAOpNFmw/uGe10DTJne8xDuuxn+T2kve9OyLL5uC7xyz7CNbj3v/w978/HQu2zaqPBWwfOWDy7T+H\nbj3CfRbLRT+O8VhlqVAsx2p9xdKxYHOsMgdsHzng6GK5t6pfK27j4089HRwLxsexAFgVb94BAKCE\nYgkAQAnFEgCAEoolAAAlFEsAAEoolgAAlFAsAQAooVgCAFBCsQQAoIRiCcCKXMzwvfETy2iX6Xw/\nrZIcjHupzcBkwfZjf1e4r3Ebn3t3tu8K30UyQLLOHEyT3Fn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rVWpJY2zQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0b6484c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "# Prior: (in red)\n",
    "prior_p = [0.2, 0.5, 0.2, 0.05, 0.05]\n",
    "showbar(ax, height=prior_p, color='red')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABaJJREFUeJzt3M+rpXMcB/D3NUN+3BuJQtRYWihKFiITJUnyL1jYWigL\nu7OzkpWdLERWIrJTTqTQxORnVpTCpEgzKRtj8Zw007j33Lk+53yec5/Xq545Zzr3nvuu59Nz3uf7\nPOckAAAAAAAAAAAAAAAAAAAAjNfWksfPriUFAACbYtf+eMk6UwAAcHgd3d+PWbicrnPflJiDaTID\nJOaAgTlg75PdViwBACihWAKwIs8n2cmwwmEb57az2E9QY58f3rHcPV1Oe2AGSA42BztJzqwgC7W2\nk5ze5886HrD17z+7ProHxXLyHEQwAyQHm4NlLzGMx0H2qePBNO1dLPf54R0A+B9m3QG4wKw7AIeR\naywBACihWAIAUEKxBACghGIJAEAJxRIAgBKKJQAAJRRLAABKKJYAAJRQLAEAKKFYAgBQQrEEAKCE\nYgkAQAnFEgCAEoolAAAlFEsAAEoolgAAlFAsAQAooVgCAFBCsQQAoIRiCQBACcUSAIASiiUAACUU\nSwAASiiWAACUUCwBACihWAIAUEKxBACghGIJAEAJxRIAgBKKJQAAJRRLAABKKJYAAJRQLAEAKKFY\nAgBQQrEEAKCEYgkAQAnFEgCAEoolAAAlFEsAAEoolgAAlFAsAQAooVgCAFBCsQQAoI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7CWt2T5LEM19e9nuSBJK+0JqLL\nz4vbX5O8meTuxixsoGOxYjllWxlePF7oDkKr65Jcs7h/RZIPkjzYF4dm98eK5VRdmWRncf+qJB8l\neagvDpvm9SQ/JfkryY9JnuiNQ4N7M1xPdTLDV0t8nuTh1kR0uD3JZxnm4IsM19kxXffHp8Kn6tYM\nx4GTGb6C7tneOAAAAAAAAAAAAAAAAAAAAAAAAAAAsLn+AXLapcFu6hcVAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xadf683ac>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "pmea = [0.05, 0.05, 0.1, 0.6, 0.2] # Measurement\n",
    "showbar(ax, height=pmea, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Posterior: prior probability * measurement probabilit ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.01   0.025  0.02   0.035  0.005]\n"
     ]
    }
   ],
   "source": [
    "post_p = np.array(pmea)*np.array(prior_p)\n",
    "print post_p"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Posterior: prior probability * measurement probability / sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Posterior:  [ 0.10526316  0.26315789  0.21052632  0.36842105  0.05263158]\n"
     ]
    }
   ],
   "source": [
    "post_p = post_p / sum(post_p)\n",
    "#print 'Sum of Posterior: ',sum(post_p)\n",
    "print 'Posterior: ', post_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Posterior:  [ 0.10526316  0.26315789  0.21052632  0.36842105  0.05263158]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABalJREFUeJzt3TGLXGUUBuB3kygaNyiioKIQSwtBQSwkIUFBRET8Cxa2\nFoKFXTorSWUnFqKkEkWxExwUwUgwIWrESkFQg6CIQbBxLe4gSZGdzebcOXd2ngdmZ2A24cA9zLzz\nzfedTQAAAAAAAAAAAAAAAAAAAJiujQXPby2lCgAAVsVV8+O+ZVYBAMDedWBnv2bhcn1d/qFEH6wn\nPUCiDxjoA7b/stuKJQAAJQRLAABKCJYAAJQQLAEAKCFYAgBQQrAEAKCEYAkAQAnBEgCAEoIlAAAl\nBEsAAEoIlgAAlBAsAQAoIVgCAFBCsAQAoIRgCQBACcESAIASgiUAACUESwAASgiWAACUECwBACgh\nWAIAUEKwBACghGAJAEAJwRIAgBKCJQAAJQRLAABKCJYAAJQQLAEAKCFYAgBQQrAEYCSvJTmUZMNt\nsrdD8+sENTYWPL91xR1r6PIW0QfrSQ+Q7K4PDiW5NEIt1NpM8tcOf9frARv//7jqs9sQLNeeFxH0\nAMnu+mDRWwzTsZtr6vVgPW0fLA8srxAA1tWWDDI5G3I/I7DHEgCAEoIlAAAlBEsAAEoIlgAAlBAs\nAQAoIVgyAkORp30zEBmAcZhjyQKGIu9NBiJzra5vjqVxQ9Nz5bghcyzZKQPSuS6GIu9d3ki4FoLl\nXiNYsjsGpNPIm8m0GIgMwJjssQQAoIRgCYzAAa7p3xziAurZY8kC9lXtJcvbU+UA12oY+xCX14Ip\ns8eS3dl+j6UVS2AEQuVqcJ2AWg7vAKOyUjU9DnEBY7FiCQBACcESAIASgiUAACUESwAASgiWAACU\nKA6WhiJP/2Yo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Z9hnx/o6\nFqfC19X9GV4HzmUYQfdKbzkAAAAAAAAAAAAAAAAAAAAAAAAAALC6/gNkudQWcs7fIAAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xae8d46ec>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def meas(prior_p, pmea):\n",
    "    post_p = np.array(pmea)*np.array(prior_p)\n",
    "    post_p = post_p / sum(post_p)\n",
    "    return post_p\n",
    "\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "post_p = meas(prior_p, pmea)\n",
    "print 'Posterior: ', post_p\n",
    "showbar(ax, height=post_p, color='yellow')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Motion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Accurate: shifting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P: \n",
      "[ 0.10526316  0.26315789  0.21052632  0.36842105  0.05263158]\n",
      "P after moving 1 step: \n",
      "[ 0.05263158  0.10526316  0.26315789  0.21052632  0.36842105]\n"
     ]
    }
   ],
   "source": [
    "def move(p, step):\n",
    "    q= [ ] #Start with empty list\n",
    "    for i in range(len(p)):\n",
    "        q.append(p[(i-step) % len (p)]) #cycle\n",
    "    return np.array(q)\n",
    "\n",
    "print 'P: \\n', post_p\n",
    "p_after_move1 = move(post_p, 1)\n",
    "print 'P after moving 1 step: \\n', p_after_move1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "input_collapsed": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\n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dyl0OmXz48CE+fvwYERGfP3+Ohw8fRrVazVwVrXT+/PmYnJyM169fx61bt2JgYCBu3LiRuyxa\nbG5uLmZmZiIi4tOnT/HgwQOTY/4PwXIRQ0ND8fvvv8erV69iy5Ytcf369dwl0WJjY2Nx8+bNePz4\ncVSr1ahWq3H//v3cZdFi7969i4GBgahUKtHT0xODg4Oxd+/e3GWRUalUyl0CGbx//z76+vr++1pw\n8ODB2L9/f+6yCse4IQAAkrBjCQBAEoIlAABJCJYAACQhWAIAkIRgCQBAEoIlAABJCJYAACTxBzjw\nplvMswwXAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0d3dd6c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "showbar(ax, height=p_after_move1, color='yellow')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Inaccurate: convolution"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$P(X_{i+s} \\mid X_i)=0.8$\n",
    "\n",
    "$P(X_{i+s+1} \\mid X_i)=0.1$\n",
    "\n",
    "$P(X_{i+s-1} \\mid X_i)=0.1$\n",
    "\n",
    "s: step"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "input_collapsed": true
   },
   "source": [
    "* Exact position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABi9JREFUeJzt3L9rk+0ex/FvilOJiILWZxB0tP4gQbEgdmgVFy0ouhSk\ng/oH6Oikk4siKDg5COLgKEVUFDRY6iCWCm4uCi1awUForKLWnOHhn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+ajX6zE0NFR6CoWsX78+tm7dGvV6PXbs2FF6TkfyzzsLGBsbi2q1GiMjI/H8+fPScyhg\nZmYmZmZmolarRbPZjG3btsXNmzdj48aNpafRZnNzc9Hd3R1fv36NXbt2xfnz52PXrl2lZ9FmFy5c\niImJiZidnY3R0dHScyhgw4YNMTExEatWrSo9pWM5sVxAf39/rFy5svQMClq7dm3UarWIiKhWq7Fx\n48Z4/fp14VWU0N3dHRERnz9/jvn5eW8qS9D09HTcvn07jh8/vuhv+PHn8/gvTljCD3j16lVMTk5G\nX19f6SkU8O3bt6jVatHT0xMDAwPR29tbehJtdvLkyTh37lx0dXnbXMoqlUrs2bMntm/fHleuXCk9\npyN5hsB3NJvNOHz4cFy8eDGq1WrpORTQ1dUVz549i+np6Xj06FE0Go3Sk2ijW7duxZo1a6Jerzut\nWuLGx8djcnIy7ty5E5cvX46xsbHSkzqOsIRFfPnyJQ4dOhRHjhyJAwcOlJ5DYStWrIh9+/bF06dP\nS0+hjR4/fhyjo6OxYcOGGB4ejgcPHsTIyEjpWRTw119/RUTE6tWr4+DBg/HkyZPCizqPsIQFtFqt\nOHbsWPT29saJEydKz6GQd+/exfv37yMi4uPHj3H//v2o1+uFV9FOZ8+ejampqXj58mXcuHEjBgcH\n49q1a6Vn0WZzc3MxOzsbEREfPnyIe/fu+eWY/0FYLmB4eDh27twZL168iHXr1sXVq1dLT6LNxsfH\n4/r16/Hw4cOo1+tRr9fj7t27pWfRZm/evInBwcGo1WrR19cXQ0NDsXv37tKzKKhSqZSeQAFv376N\n/v7+/7wW7N+/P/bu3Vt6Vsfxc0MAAKRwYgkAQAphCQBACmEJAEAKYQkAQAphCQBACmEJAEAKYQkA\nQIp/AV3XMP6xRDtcAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0d1b04c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "# original: cell 2\n",
    "showbar(ax, 2, height=1, color='red')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Move 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABtpJREFUeJzt3b1r0+0ex/FvipMkiIJWB8GO1gcSFAs37dAqLlpQdCmI\ng/oH6OhkJhetoODkIIiDoxRRUdCg6CCWCm4uCooP4CAkVlFrznCfB2/u09jjuZIrpq8XZKrKB35X\n7ZtfHlpoNpvNAACA/1Nf7gEAAPQGYQkAQBLCEgCAJIQlAABJCEsAAJJYknsAvadUKkWj0cg9gxaK\nxWLU6/XcMwDoMQUfN0RqhUIh9wQWwLc+AKm5Y0lbSZfuIvkBaCevsQQAIAlhCQBAEsISAIAkhCUA\nAEkISwAAkhCWAAAkISwBAEhCWAIAkISwBAAgCWEJAEASwhJIbnJyMkqlUhQKBY8ufZRKpZicnMx9\nVIAeU2g2m36dM0kVCv/5jdQOV3f58XeFt/Nbv1QqRaPRaNu/TxrFYjHq9XruGUAPEZYkJyy7V6fC\n8sczQHfzIwBIaUnuAUCPq+YewN9Ucw8AelXLsPR0FvQudxWJcA6A/12rZzpavnlHVAIAsFDeFQ4A\nQBILfI2lF3cvXn95u8cv/B26169cT2eg97TzHNB7nANa///ujiUAAEkISwAAkhCWAAAkISwBAEhC\nWAIAkISwBAAgCWEJAEASwhIAgCSEJQAASQhLAACSEJYAACQhLAEASEJYAgCQhLAEACAJYQkAQBLC\nEgCAJIQlAABJCEsAAJIQlgAAJCEsAQBIQlgCAJCEsAQAIAlhCQBAEsISAIAkhCUAAEkISwAAkhCW\nAAAkISwBAEhCWAIAkISwBAAg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PnsSrV6/i3r17UavVck+ig65duxarVq2KSqXibtUi\n9+DBg5iZmYkbN27E+fPn4/79+7kndR1hCS18/fo19u3bFwcOHIg9e/bknkNmy5Yti127dsXjx49z\nT6GDHj58GFNTUzEwMBATExNx586dOHjwYO5ZZLBmzZqIiFi5cmXs3bs3Hj16lHlR9xGWMI9msxmH\nDx+OwcHBOHr0aO45ZPL+/fv48OFDRER8+vQpbt++HZVKJfMqOunkyZPx8uXLeP78eVy5ciXGxsbi\n0qVLuWfRYbOzs1Gv1yMi4uPHj3Hr1i2fHPNfCMt5TExMxB9//BHPnj2LtWvXxsWLF3NPosMePHgQ\nly9fjrt370alUolKpRI3b97MPYsOe/PmTYyNjUW5XI6hoaEYHx+P7du3555FRoVCIfcEMnj37l2M\njIz8+/+C3bt3x86dO3PP6jo+bggAgCTcsQQAIAlhCQBAEsISAIAkhCUAAEkISwAAkhCWAAAkISwB\nAEjiH/xUZTzIYmswAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb15fa60c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "# original: cell 2\n",
    "showbar(ax, 2, height=1, color='red')\n",
    "\n",
    "# after move 1 \n",
    "s = 1\n",
    "newpos = 2 + s + np.array([-1, 0, 1])\n",
    "move_prob = [0.1, 0.8, 0.1]\n",
    "showbar(ax, newpos, height=move_prob, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Move 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABwtJRE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vXT8+PF4+fJlPH/+PC5duhSbN2+OCxcu5I5Fj42O\njkar1YqIiA8fPsTNmzf9csy/UCzHsXfv3li/fn08e/YslixZEufPn88diR67f/9+XLx4Me7cuRP1\nej3q9XrcuHEjdyx67M2bN7F58+ao1WoxMDAQg4ODsWXLltyxyKgoitwRyODt27excePG/68FO3bs\niG3btuWOVTp+bggAgCTsWAIAkIRiCQBAEoolAABJKJYAACShWAIAkIRiCQBAEoolAABJ/Ac17nw1\nLO6XzgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0d7b6ec>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "# original: cell 2\n",
    "showbar(ax, 2, height=1, color='red')\n",
    "\n",
    "# after move 2 \n",
    "s = 2\n",
    "newpos = 2 + s + np.array([-1, 0, 1])\n",
    "move_prob = [0.1, 0.8, 0.1]\n",
    "showbar(ax, newpos, height=move_prob, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Inaccurate position"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false,
    "input_collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAButJREFUeJzt3c2rTf8ewPHPkpH2SZSngWLoeGjvyCk5Aw+ZoIiJkgH+\nAIZGzsiEn6KMDJQMDCUhih0xEFFmJhR5KAN1joc87Tvg3p97u2cfP7/P3t/1c16vWrW19+FzWl9r\nvy1nr1V1Op1OAADA3zSl9AAAAPwehCUAACmEJQAAKYQlAAAphCUAACmmdnuyqqp+zQEAwD9AtwsK\nOWMJAECKrmcs/+RSl5PXj2etrYPJyRog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n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0d6f4ac>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "# original:\n",
    "ini_pos = [0.2, 0.6, 0.2, 0, 0]\n",
    "showbar(ax, height=ini_pos, color='red')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def move_v2(p, step):\n",
    "    #Introduce auxiliary variable s\n",
    "    q= []\n",
    "    #Add exact probability\n",
    "    pExact = 0.8\n",
    "    #Add overshoot probability\n",
    "    pOvershoot = 0.1\n",
    "    #Add undershoot probability\n",
    "    pUndershoot = 0.1\n",
    "\n",
    "    for i in range(len(p)):\n",
    "        s = pExact * p[(i-step) % len(p)]\n",
    "        s = s + pOvershoot * p[(i-step-1) % len(p)]\n",
    "        s = s + pUndershoot * p[(i-step+1) % len(p)]\n",
    "        q.append(s)\n",
    "    return q"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P: \n",
      "[0.2, 0.6, 0.2, 0, 0]\n",
      "P after moving: \n",
      "[0.020000000000000004, 0.22000000000000003, 0.52, 0.22000000000000003, 0.020000000000000004]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABw5JREFUeJzt3M2LjX8fB/DPJSudSZSnhWJpPHROZOoXi0E2KGKjZIE/\ngKWVs7LxUJSVhZKFpSREcSIWIsrOhiIPZaFmPOTp3Au6b/f9u88xze8z53vMvF511dF1neld34/r\nvPteM6dqt9vtAACAf2ha6QAAAEwOiiUAACkUSwAAUi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r15eORUFVVZWOQAFv3ryJtWvX/vte\nsHnz5ti4cWPpWH3H1w0BAJDCjiUAACkUSwAAUiiWAACkUCwBAEihWAIAkEKxBAAghWIJAECKfwEL\nXG5TWnhDuAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb16d9ecc>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "\n",
    "# original:\n",
    "ini_pos = [0.2, 0.6, 0.2, 0, 0]\n",
    "\n",
    "# after move 2 \n",
    "s = 1\n",
    "print 'P: \\n', ini_pos\n",
    "p_after_move = move_v2(ini_pos, s)\n",
    "print 'P after moving: \\n', p_after_move\n",
    "showbar(ax, height=p_after_move, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Iterate Measurement + Motion "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.04819277  0.24096386  0.6746988   0.02409639  0.01204819]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABu1JREFUeJzt3LtrVOsaB+B3xEomiIK3QtDSeGEGxYCYIlFsVFC0EcRC\n/QOUU1k5lY0X2IKVhSAWliKioqCDooUYItjZKChewEJIvOBtThH32eeWUbLfmW9MngcWBGYy+cH3\nZvLLt9asSqvVagUAAPxNs0oHAABgelAsAQBIoVgCAJBCsQQAIIViCQBAitntHqxUKt3KAQDAb6Dd\nDYXsWAIAkKLtjuVf3Opy5vr3XWtzMDOZASLMARPMAe3PZtuxBAAghWIJAEAKxRIAgBSKJdABJyOi\nLyauxXH05tH3Y50A8lRab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figure at 0xb0d223ec>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Prior\n",
    "prior_p = [0.2, 0.5, 0.2, 0.05, 0.05]\n",
    "# Measurement 1\n",
    "pmea1 = [0.05, 0.1, 0.7, 0.1, 0.05] # Measurement\n",
    "# Moves right 1\n",
    "s1 = 1\n",
    "# Measurement 2\n",
    "pmea2 = [0.05, 0.05, 0.1, 0.7, 0.1] # Measurement\n",
    "# Moves right 2\n",
    "s2 = 2\n",
    "# Measurement 3\n",
    "pmea3 = [0.7, 0.1, 0.05, 0.05, 0.1 ] # Measurement\n",
    "\n",
    "post_p1 = meas(prior_p, pmea1)\n",
    "print post_p1\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "showbar(ax, height=post_p1, color='green')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.016867469879518079, 0.063855421686747002, 0.2650602409638555, 0.56626506024096379, 0.087951807228915671]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABwhJREFUeJzt3L1rVNsaB+B3i1WYIAoaLQQtjR/MoBgQLYxiowFFm4Ck\nUP8A5VZWTmXjBxzBykIQC0sRUVHQwaCFGCLY2SgkaAQLITGKX3MLved67rmZeL1rZm2T54ENA3sT\nfrDe7Pxmzc4UzWazGQAA8H9akDsAAABzg2IJAEASiiUAAEkolgAAJKFYAgCQxMJWJ4ui6FQOAAB+\nA62+UMiOJQAASbTcsfw3X3U5f/24a20O5iczQIQ54BtzQOtPs+1YAgCQhGIJAEASiiUAAEkolgAA\nJKFYAgCQhGIJAEASiiUAAEkolgAAJKFYAgCQhGIJAEASiiUAAEkolgAAJKFYA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LAACSUCwBAEhCsZzBoUOHoqenJ9avX587\nCpmMjY3F9u3bY+3atbFu3bo4d+5c7khk8OHDh+jr64tqtRq9vb1x/Pjx3JHI5MuXL1Gr1WJgYCB3\nFDJZtWpVbNiwIWq1WmzevDl3nFLyzzszGB4ejkqlEkNDQ/H06dPccchgYmIiJiYmolqtxtTUVGzc\nuDGuXr0aa9asyR2NDpueno6urq74/PlzbN26NU6fPh1bt27NHYsOO3v2bIyMjMTk5GRcu3Ytdxwy\nWL16dYyMjMSSJUtyRyktO5Yz2LZtWyxevDh3DDJavnx5VKvViIioVCqxZs2aePnyZeZU5NDV1RUR\nER8/fowvX774ozIPjY+Px40bN+LIkSMtv8OPuc/6t6ZYwk948eJFjI6ORl9fX+4oZPD169eoVqvR\n09MT27dvj97e3tyR6LBjx47FqVOnYsECfzbns6IoYufOnbFp06a4cOFC7jil5DcEZjE1NRUHDhyI\nP/74IyqVSu44ZLBgwYJ48uRJjI+Px/3796PRaOSORAddv349li1bFrVazW7VPPfgwYMYHR2Nmzdv\nxvnz52N4eDh3pNJRLKGFT58+xf79++PgwYOxd+/e3HHIbNGiRbF79+54/Phx7ih00MOHD+PatWux\nevXqGBwcjLt378bQ0FDuWGSwYsWKiIhYunRp7Nu3Lx49epQ5UfkoljCDZrMZhw8fjt7e3jh69Gju\nOGTy5s2bePv2bUREvH//Pu7cuRO1Wi1zKjrp5MmTMTY2Fs+fP48rV65Ef39/XLp0KXcsOmx6ejom\nJycjIuLdu3dx+/Zt3xzzXyiWMxgcHIwtW7bEs2fPYuXKlXHx4sXckeiwBw8exOXLl+PevXtRq9Wi\nVqvFrVu3cseiw169ehX9/f1RrVajr68vBgYGYseOHbljkVFRFLkjkMHr169j27Ztf94L9uzZE7t2\n7codq3R83RAAAEnYsQQAIAnFEgCAJBRLAACSUCwBAEhCsQQAIAnFEgCAJBRLAACS+CcewmOHYKdy\n/gAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0ceecec>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "post_p2 = move_v2(post_p1, s1)\n",
    "print post_p2\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "showbar(ax, height=post_p2, color='green')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.00193557  0.00732753  0.0608323   0.90971934  0.02018526]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABpxJREFUeJzt3b9rU/sfx/F3yp1KiihodRDs2PqDBMWCtEOruGhB0aUg\nHdQ/QLmTk72Li15BwclBEAdHKaKioMFSB7FUcHNRaNEKDkJjFbXmDt7vlwv3NvZ6P8knto8HFAoJ\n8oJz2jw5pyaFWq1WCwAA+I/acg8AAGB5EJYAACQhLAEASEJYAgCQhLAEACCJX3IPAGB56ujoiGq1\nmnsG31EsFmNubi73DJaJgrcbAqARCoVC7gkskRQgFVcsAWi80dwD+JvR3ANYjvyNJQAASQhLAACS\nEJYAACQhLAEASEJYAgCQhLAEACAJYQkAQBLCEgCAJOq+QbqP4wKA5c+nJPFv1PukprpXLEUlAABL\n5VY4AABJLPGzwn04/cr119sjzoOVyTlAxI+dB26v/jx+5Jj6fbAy1f+5dsUSAIAkhCUAAEkISwAA\nkhCWAAAkISwBAEhCWAIAkISwBAAgCWEJAEASwhIAgCSEJQAASQhLAACSEJYAACQhLAEASEJYAgCQ\nhLAEACAJYQkAQBLCEgCAJIQlAABJCEsAAJIQlgAAJCEsAQBIQlgCAJCEsAQAIAlhCQBAEsISAIAk\nhCUAAEkISwAAkhCWAAAkISwBAEhCWAIAkISwBAAgCWEJAEASwhIAgCSEJQAASQhLAACSEJYAAC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ITA\nd1Sr1Th8+HBcuHAhisVi7jlk0NbWFk+fPo2ZmZl4+PBhVCqV3JNoops3b8a6deuiXC67WrXCTUxM\nxNTUVNy+fTsuXboU4+PjuSe1HGEJdXz+/DkOHToUR44ciQMHDuSeQ2arVq2Kffv2xZMnT3JPoYke\nPXoUY2Nj0dXVFcPDw3H//v0YGRnJPYsMNmzYEBERa9eujYMHD8bjx48zL2o9whIWUavV4tixY9HT\n0xMnTpzIPYdM3r59G+/evYuIiA8fPsS9e/eiXC5nXkUznTlzJqanp+PFixdx/fr1GBwcjKtXr+ae\nRZPNz8/H3NxcRES8f/8+7t69651j/oGwXMTw8HDs2rUrnj9/Hhs3bowrV67knkSTTUxMxLVr1+LB\ngwdRLpejXC7HnTt3cs+iyV6/fh2Dg4NRKpWit7c3hoaGYvfu3blnkVGhUMg9gQzevHkT/f39//9d\nsH///ti7d2/uWS3H2w0BAJCEK5YAACQhLAEASEJYAgCQhLAEACAJYQkAQBLCEgCAJIQlAABJ/AGV\nFkyM0SaxTwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0c59d2c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "post_p3 = meas(post_p2, pmea2)\n",
    "print post_p3\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "showbar(ax, height=post_p3, color='green')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.73587722936540856, 0.10731370109221623, 0.0042997373150836463, 0.012138808240011068, 0.14037052398728056]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABs9JREFUeJzt3c+LzW0fwPHPme6VjkT5tV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6LL7t27FxcuXIjbt29HvV6P\ner0e169fLz0WXfb69esYGhqKWq0WAwMDsX379ti0aVPpsSioUqmUHoEC3rx5Exs2bPjjvWDbtm2x\nZcuW0mP1HLcbAgAghRNLAABSCEsAAFIISwAAUghLAABSCEsAAFIISwAAUghLAABS/Adbjk9HYoHL\n4AAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0ce6cac>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "post_p4 = move_v2(post_p3, s2)\n",
    "print post_p4\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "showbar(ax, height=post_p4, color='green')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  9.52672201e-01   1.98470179e-02   3.97605164e-04   1.12249947e-03\n",
      "   2.59606767e-02]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAApYAAAByCAYAAADpuJG3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAABrNJREFUeJzt3b1rVG0awOF7ZKswQRQ0WghaJn4wg2JAtPADGw0o2gQk\nhfoHaGlltrHRFRSsLASxsBQRFQUdFC3EEMHORiFBI1gIGT9Q42zhu/vuu2xidO/MM8brgoHIzBxu\nOE9yfjlnPKm0Wq1WAADA/2lB6QEAAJgfhCUAACmEJQAAKYQlAAAphCUAACn+lrmx7u7uaDabmZtk\nDlSr1ZicnCw9BgAwz1QybzdUqVSyNsUcc5cpACBb6hnLvxiesy3zs4ZLDwAAzGc+YwkAQAphCQBA\nCmEJAEAKYQkAQAphCQBACmEJAEAKYQkAQAphCQBACmEJAEAKYQkAQAphCQBAihn/Vnh3d3c0m812\nzUIbVSqV0iMAAL+gVqs17XMznrEUlQAAzJZL4QAApJjxUv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YmIiarVaNJvNWL9+fVy5ciV6e3tLj0abvX//Prq6uuLLly+xefPmOHXq\nVGzevLn0WLTZ6dOnY2RkJCYnJ+Pq1aulx6GAVatWxcjISCxevLj0KB3LGctpbNmyJRYtWlR6DApa\ntmxZ1Gq1iIioVqvR29sbL1++LDwVJXR1dUVExKdPn2JqaspB5Tc0Pj4e169fj8OHD894Dz/mP/t/\nZsISZuHFixcxOjoa/f39pUehgK9fv0atVouenp7YunVr9PX1lR6JNjt69GicPHkyFixw2PydVSqV\n2LFjR2zYsCHOnz9fepyO5DsEvqPZbMb+/fvjzJkzUa1WS49DAQsWLIgnT57E+Ph43Lt3LxqNRumR\naKNr167F0qVLo16vO1v1m3vw4EGMjo7GjRs34ty5c3H//v3SI3UcYQkz+Pz5c+zbty8OHDgQe/bs\nKT0OhS1cuDB27doVjx8/Lj0KbfTw4cO4evVqrFq1KgYHB+POnTsxNDRUeiwKWL58eURELFmyJPbu\n3RuPHj0qPFHnEZYwjVarFYcOHYq+vr44cuRI6XEo5M2bN/H27duIiPjw4UPcvn076vV64alopxMn\nTsTY2Fg8f/48Ll++HNu2bYuLFy+WHos2e//+fUxOTkZExLt37+LWrVvuHPM/CMtpDA4OxqZNm+LZ\ns2exYsWKuHDhQumRaLMHDx7EpUuX4u7du1Gv16Ner8fNmzdLj0WbvXr1KrZt2xa1Wi36+/tjYGAg\ntm/fXnosCqpUKqVHoIDXr1/Hli1b/v2zYPfu3bFz587SY3UctxsCACCFM5YAAKQQlgAApBCWAACk\nEJYAAKQQlgAApBCWAACkEJYAAKT4J/rJVmYYPezyAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xb0af7b2c>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "post_p5 = meas(post_p4, pmea3)\n",
    "print post_p5\n",
    "ax = plt.figure().add_axes((0.1, 0.2, 1.5, 0.3))\n",
    "show_world(ax)\n",
    "showbar(ax, height=post_p5, color='green')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Positioning: Iteration of Measurement + Motion\n",
    "* Measurement: Production followed by normalization\n",
    "\n",
    "  Bayes's rule\n",
    "\n",
    "  $P(x|Z)=\\frac{P(Z|x)P(x)}{P(Z)}$\n",
    "\n",
    "  x=cell\n",
    "\n",
    "  Z=measurement\n",
    "\n",
    "  $P(x|Z)=$probability of cell after measurment\n",
    "\n",
    "  $P(x)=$probability of cell before measurment\n",
    "\n",
    "  $P(Z|x)=$probability of measurment on the condition of cell\n",
    "\n",
    "  $P(Z)=\\sum P(Z|x)P(x)$total probability of making measurement \"Z\"\n",
    "\n",
    "* Motion: Convolution\n",
    "  \n",
    "  Theorem of Total Probability\n",
    "  \n",
    "  $P(x_i^{t})=\\sum_jP(x_j^{t-1})P(x_i|x_j)$\n",
    "  \n",
    "  $P(x_i|x_j)=$probability of moving from cell $x_j$ to cell $x_i$\n",
    "  \n",
    "  $t=$time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Resources"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* [1] https://docs.python.org/2.7/\n",
    "* [2] http://ipython.org/documentation.html\n",
    "* [3] http://nbviewer.ipython.org/github/ipython/ipython/blob/3.x/examples/Notebook/Index.ipynb\n",
    "* [4] http://docs.scipy.org/doc/numpy/reference/\n",
    "* [5] http://docs.scipy.org/doc/scipy/reference/\n",
    "* [6] http://matplotlib.org/contents.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "application/json": {
       "Software versions": [
        {
         "module": "Python",
         "version": "2.7.11+ 64bit [GCC 5.3.1 20160429]"
        },
        {
         "module": "IPython",
         "version": "5.1.0"
        },
        {
         "module": "OS",
         "version": "Linux 4.4.0 2 deepin amd64 x86_64 with debian 8.0"
        },
        {
         "module": "scipy",
         "version": "0.18.0"
        },
        {
         "module": "numpy",
         "version": "1.11.1"
        },
        {
         "module": "matplotlib",
         "version": "1.5.2"
        }
       ]
      },
      "text/html": [
       "<table><tr><th>Software</th><th>Version</th></tr><tr><td>Python</td><td>2.7.11+ 64bit [GCC 5.3.1 20160429]</td></tr><tr><td>IPython</td><td>5.1.0</td></tr><tr><td>OS</td><td>Linux 4.4.0 2 deepin amd64 x86_64 with debian 8.0</td></tr><tr><td>scipy</td><td>0.18.0</td></tr><tr><td>numpy</td><td>1.11.1</td></tr><tr><td>matplotlib</td><td>1.5.2</td></tr><tr><td colspan='2'>Sun Sep 18 22:16:56 2016 CST</td></tr></table>"
      ],
      "text/latex": [
       "\\begin{tabular}{|l|l|}\\hline\n",
       "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n",
       "Python & 2.7.11+ 64bit [GCC 5.3.1 20160429] \\\\ \\hline\n",
       "IPython & 5.1.0 \\\\ \\hline\n",
       "OS & Linux 4.4.0 2 deepin amd64 x86\\_64 with debian 8.0 \\\\ \\hline\n",
       "scipy & 0.18.0 \\\\ \\hline\n",
       "numpy & 1.11.1 \\\\ \\hline\n",
       "matplotlib & 1.5.2 \\\\ \\hline\n",
       "\\hline \\multicolumn{2}{|l|}{Sun Sep 18 22:16:56 2016 CST} \\\\ \\hline\n",
       "\\end{tabular}\n"
      ],
      "text/plain": [
       "Software versions\n",
       "Python 2.7.11+ 64bit [GCC 5.3.1 20160429]\n",
       "IPython 5.1.0\n",
       "OS Linux 4.4.0 2 deepin amd64 x86_64 with debian 8.0\n",
       "scipy 0.18.0\n",
       "numpy 1.11.1\n",
       "matplotlib 1.5.2\n",
       "Sun Sep 18 22:16:56 2016 CST"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Install the version_information package using pip:\n",
    "# pip install version_information\n",
    "# or, alternatively, use the %install_ext IPython command (deprecated):\n",
    "# %install_ext http://raw.github.com/jrjohansson/version_information/master/version_information.py\n",
    "\n",
    "%load_ext version_information\n",
    "%version_information scipy, numpy, matplotlib"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11+"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
